package com.zxcl.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zxcl.domain.Member;
import com.zxcl.dto.MemberUpdateDTO;
import com.zxcl.model.Result;
import com.zxcl.service.MemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

/**
 * 描述: [会员管理接口]
 * 作者: zxcl
 */
@RestController
@RequestMapping("p/user")
@Api(tags = "会员管理接口")
public class MemberController {
    @Autowired
    private MemberService memberService;

    @PutMapping("setUserInfo")
    @ApiOperation("更新会员的信息")
    public Result<String> updateMember(@RequestBody MemberUpdateDTO memberUpdateDTO) {
        Integer i = memberService.updateMember(memberUpdateDTO);
        return Result.handle(i > 0);
    }


    ////////////////// feign //////////////
    @GetMapping("getMembersByOpenIds")
    @ApiOperation("根据openIds获取会员的信息集合")
    Result<List<Member>> getMembersByOpenIds(@RequestParam("openIds") Set<String> openIds) {
        List<Member> memberList = memberService.list(new LambdaQueryWrapper<Member>()
                .select(Member::getOpenId, Member::getNickName, Member::getPic)
                .in(Member::getOpenId, openIds)
        );
        return Result.success(memberList);
    }

}
